package com.yizhubao.app.wxapi;

import android.app.Activity;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.yizhubao.app.app.YZBApp;
import com.yizhubao.app.events.WXLoginEvent;

import org.greenrobot.eventbus.EventBus;

import h.framework.pacy.utils.LogUtil;

/**
 * 创建人: PACY
 * 创建时间: 6/10/21 4:03 PM
 * 邮箱: pengwwe457621023@qq.com
 * 类描述:
 */
public class WXEntryActivity extends AppCompatActivity implements IWXAPIEventHandler {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        YZBApp.api.handleIntent(getIntent(),this);
    }

    @Override
    public void onReq(BaseReq baseReq) {

    }

    @Override
    public void onResp(BaseResp resp) {
        switch (resp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                LogUtil.i("onResp OK");
                if (resp instanceof SendAuth.Resp) {
                    SendAuth.Resp newResp = (SendAuth.Resp) resp;
                    //获取微信传回的code
                    String code = newResp.code;
                    LogUtil.i("onResp code="+code);
                    EventBus.getDefault().post(new WXLoginEvent(code));
                }
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                LogUtil.i("onResp ERR_USER_CANCEL");
                //发送取消
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                LogUtil.i("onResp ERR_AUTH_DENIED");
                //发送被拒绝
                break;
            default:
                LogUtil.i("onResp default errCode " + resp.errCode);
                //发送返回
                break;
        }
        finish();
    }
}
